package com.shd.edanpei.presenter;


import com.shd.edanpei.base.BasePresenterImpl;
import com.shd.edanpei.base.network.api.ApiCreator;
import com.shd.edanpei.base.network.exception.ResponeThrowable;
import com.shd.edanpei.base.network.rx.BaseObserver;
import com.shd.edanpei.base.network.rx.RxTransformer;
import com.shd.edanpei.bean.UrlModel;
import com.shd.edanpei.presenter.contract.WebContract;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by mc on 2018/6/7.
 * yang-wen-wen
 */

public class WebPresenter extends BasePresenterImpl<WebContract.WebIView>
        implements WebContract.WebIPresenter {

    public WebPresenter(WebContract.WebIView mView) {
        super(mView);
    }


    @Override
    public void getUrlInfo(final int type) {
        if(3==type){//用户协议新街口不传参
            ApiCreator.getApi().getLoadingUserAgreement("")
                    .compose(RxTransformer.<UrlModel>errorHandle())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObserver<UrlModel>() {
                        @Override
                        protected void onSuccess(UrlModel data) {
                            mBaseIView.setUrlInfo(data);
                        }
                        @Override
                        public void onFailure(ResponeThrowable throwable) {
                            super.onFailure(throwable);
                            //加载失败

                        }
                    });
        }else {
            ApiCreator.getApi().getUrl(type)
                    .compose(RxTransformer.<UrlModel>errorHandle())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObserver<UrlModel>() {
                        @Override
                        protected void onSuccess(UrlModel data) {
                            mBaseIView.setUrlInfo(data);
                        }

                        @Override
                        public void onFailure(ResponeThrowable throwable) {
                            super.onFailure(throwable);
                            //加载失败

                        }
                    });
        }
    }
}
